package com.JQ;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class HasMapDemo02 {
    public static void main(String[] args) {
        HashMap<String,String> hm=new HashMap<>();
        hm.put("邓超","孙俪");
        hm.put("李晨","范冰冰");
        hm.put( "刘德华","柳岩");
        hm.put("黄晓明","Baby" );
        hm.put("谢霆锋","张柏芝");
        Set<String> keys = hm.keySet();
        Iterator<String> it = keys.iterator();
        while (it.hasNext()){
            String key = it.next();
            String vaule = hm.get(key);
            System.out.println(key+"-->"+vaule);
        }
        //method1(hm);
        //method2(hm, keys);
        //method3(hm);
    }

    private static void method3(HashMap<String, String> hm) {
        Set<Map.Entry<String, String>> entries = hm.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"-->"+value);
        }
    }

    private static void method2(HashMap<String, String> hm, Set<String> keys) {
        for (String key : keys) {
            String value = hm.get(key);
            System.out.println(key+"-->"+value);
        }
    }

    private static void method1(HashMap<String, String> hm) {
        hm.forEach((String key,String value)->{
            System.out.println(key+"-->"+value);
        });
    }
}
